package cn.waqwb.bwcar.config;

import cn.waqwb.bwcar.dto.DataGridResult;
import cn.waqwb.bwcar.dto.QueryDTO;
import cn.waqwb.bwcar.pojo.CarParamType;
import cn.waqwb.bwcar.pojo.CarParams;
import cn.waqwb.bwcar.service.CarParamService;
import cn.waqwb.bwcar.service.CarParamTypeService;
import cn.waqwb.bwcar.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author JokerQ
 * @date 2019/11/21 - 21:13
 */
@RestController
public class CarParamsController {
    @Autowired
    private CarParamTypeService carParamTypeService;

    @Autowired
    private CarParamService carParamService;


    @RequestMapping("/sys/params/list")
    public DataGridResult findCarParam(QueryDTO queryDTO){
        return carParamService.findByPage(queryDTO);
    }


    @RequestMapping("/sys/params/del")
    public R deleteCarParams(@RequestBody List<Integer> ids){
        for (Integer id : ids) {
            carParamService.delCarParams(id);
        }
        return R.ok();
    }

    //获取分类信息

    @RequestMapping("/sys/params/typeall")
    public R typeAll(){
        List<CarParamType> all = carParamTypeService.findAll();
        return R.ok().put("sites",all);
    }



    @RequestMapping("/sys/params/info/{id}")
    public R findById(@PathVariable("id") Integer id){
        CarParams byId = carParamService.findById(id);
        return R.ok().put("params",byId);
    }


    @RequestMapping("/sys/params/save")
    public R addCarParams(@RequestBody CarParams carParams){
        int i = carParamService.addCarParams(carParams);
        return i>0?R.ok():R.error("添加失败");
    }


    @RequestMapping("/sys/params/update")
    public R updateCarParams(@RequestBody CarParams carParams){
        int i = carParamService.updateCarParams(carParams);
        return i>0?R.ok():R.error("修改失败");
    }
}
